package com.test.service.Impl;


import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.test.domain.dto.User;
import com.test.mapper.UserMapper;
import com.test.service.UserService;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {

    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        User user = getUserByUsername(username);
        if (user == null) throw new UsernameNotFoundException("用户不存在");
        return org.springframework.security.core.userdetails.User
                .withUsername(username)
                .password(user.getPassword())
                .roles(user.getRid())
                .build();
    }
    public User getUserByUsername(String username)
    {
        return this.baseMapper.selectOne(new com.baomidou.mybatisplus.core.conditions.query.QueryWrapper<User>().eq("username",username));
    }
}
